package com.cqyc.shop.comm;

import java.io.Serializable;

public class Pager implements Serializable{
	private static final long serialVersionUID = -7202770683255736461L;
	
	public Pager() {
		this.pageSize=5;
		this.currentPage=1;
	}
	
	public Pager(Integer totalSize) {
		this.totalSize = totalSize;
	}

	public Pager(Integer pageSize, Integer currentPage, Integer totalSize) {
		this.pageSize = pageSize;
		this.currentPage = currentPage;
		this.totalSize = totalSize;
	}

	private Integer pageSize = 5;//有几行
	private Integer currentPage = 1;//当前页
	private Integer totalSize = 0;//总的个数
	
	
	/**
	 * 总的页数
	 * @return
	 */
	public Integer getTotalPage() {
		if(totalSize%pageSize==0) {
			return totalSize/pageSize;
		}else {
			return totalSize/pageSize+1;
		}
	}
	
	
	/**
	 * 前一页
	 * @return
	 */
	public Integer getPrevPage() {
		if(currentPage>1) {
			return currentPage-1;
		}else {
			return 1;
		}
	}
	
	/**
	 * 下一页
	 * @return
	 */
	public Integer getNextPage() {
		
		if (currentPage>=1 && currentPage<getTotalPage()) {
			return currentPage+1;
		} else {
			return getTotalPage();
		}
	}
	
	public Integer getPageSize() {
		return pageSize;
	}
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	public Integer getCurrentPage() {
		return currentPage<1?1:currentPage;
	}
	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}
	public Integer getTotalSize() {
		return totalSize;
	}
	public void setTotalSize(Integer totalSize) {
		this.totalSize = totalSize;
	}
}
